From b25be8a42f4ca470ebc958034ae19391e0eb22e7 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Tue, 3 Mar 2020 15:55:45 -0800 Subject: [PATCH] Add a GdkDragSurface interface This will provide functionality specific to drag icons. --- gdk/gdk.h | 1 + gdk/gdkdragsurface.c | 71 +++++++++++++++++++++++++++++++++++++ gdk/gdkdragsurface.h | 43 ++++++++++++++++++++++ gdk/gdkdragsurfaceprivate.h | 20 +++++++++++ gdk/gdksurface.c | 27 +++++++++++++- gdk/meson.build | 2 ++ 6 files changed, 163 insertions(+), 1 deletion(-) create mode 100644 gdk/gdkdragsurface.c create mode 100644 gdk/gdkdragsurface.h create mode 100644 gdk/gdkdragsurfaceprivate.h diff --git a/gdk/gdk.h b/gdk/gdk.h index 30ab0d7590..d15dd7d922 100644 --- a/gdk/gdk.h +++ b/gdk/gdk.h @@ -44,6 +44,7 @@ #include #include #include +#include #include #include #include diff --git a/gdk/gdkdragsurface.c b/gdk/gdkdragsurface.c new file mode 100644 index 0000000000..4eb3c9137f --- /dev/null +++ b/gdk/gdkdragsurface.c @@ -0,0 +1,71 @@ +/* + * Copyright © 2020 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see . + * + * Authors: Matthias Clasen + */ + +#include "config.h" + +#include "gdk-private.h" +#include "gdkdragsurfaceprivate.h" +#include "gdkintl.h" + +/** + * SECTION:gdkdragsurface + * @Short_description: Interface for drag surface surfaces + * @Title: Drag surfaces + * + * A #GdkDragSurface is a surface that is used during a + * DND operation. + */ + +G_DEFINE_INTERFACE (GdkDragSurface, gdk_drag_surface, GDK_TYPE_SURFACE) + +static gboolean +gdk_drag_surface_default_present (GdkDragSurface *drag_surface, + int width, + int height) +{ + return FALSE; +} + +static void +gdk_drag_surface_default_init (GdkDragSurfaceInterface *iface) +{ + iface->present = gdk_drag_surface_default_present; +} + +/** + * gdk_drag_surface_present: + * @drag_surface: the #GdkDragSurface to show + * @width: the unconstrained drag_surface width to layout + * @height: the unconstrained drag_surface height to layout + * + * Present @drag_surface. + * + * Returns: %FALSE if it failed to be presented, otherwise %TRUE. + */ +gboolean +gdk_drag_surface_present (GdkDragSurface *drag_surface, + int width, + int height) +{ + g_return_val_if_fail (GDK_IS_DRAG_SURFACE (drag_surface), FALSE); + g_return_val_if_fail (width > 0, FALSE); + g_return_val_if_fail (height > 0, FALSE); + + return GDK_DRAG_SURFACE_GET_IFACE (drag_surface)->present (drag_surface, width, height); +} diff --git a/gdk/gdkdragsurface.h b/gdk/gdkdragsurface.h new file mode 100644 index 0000000000..61649bff76 --- /dev/null +++ b/gdk/gdkdragsurface.h @@ -0,0 +1,43 @@ +/* + * Copyright © 2020 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see . + * + * Authors: Matthias Clasen + */ + +#ifndef __GDK_DRAG_SURFACE_H__ +#define __GDK_DRAG_SURFACE_H__ + +#if !defined(__GDK_H_INSIDE__) && !defined(GTK_COMPILATION) +#error "Only can be included directly." +#endif + +#include + +G_BEGIN_DECLS + +#define GDK_TYPE_DRAG_SURFACE (gdk_drag_surface_get_type ()) + +GDK_AVAILABLE_IN_ALL +G_DECLARE_INTERFACE (GdkDragSurface, gdk_drag_surface, GDK, DRAG_SURFACE, GObject) + +GDK_AVAILABLE_IN_ALL +gboolean gdk_drag_surface_present (GdkDragSurface *drag_icon, + int width, + int height); + +G_END_DECLS + +#endif /* __GDK_DRAG_SURFACE_H__ */ diff --git a/gdk/gdkdragsurfaceprivate.h b/gdk/gdkdragsurfaceprivate.h new file mode 100644 index 0000000000..e32cfd780c --- /dev/null +++ b/gdk/gdkdragsurfaceprivate.h @@ -0,0 +1,20 @@ +#ifndef __GDK_DRAG_SURFACE_PRIVATE_H__ +#define __GDK_DRAG_SURFACE_PRIVATE_H__ + +#include "gdkdragsurface.h" + +G_BEGIN_DECLS + + +struct _GdkDragSurfaceInterface +{ + GTypeInterface g_iface; + + gboolean (* present) (GdkDragSurface *drag_surface, + int width, + int height); +}; + +G_END_DECLS + +#endif /* __GDK_DRAG_SURFACE_PRIVATE_H__ */ diff --git a/gdk/gdksurface.c b/gdk/gdksurface.c index 4e6cce46df..850826ea85 100644 --- a/gdk/gdksurface.c +++ b/gdk/gdksurface.c @@ -32,6 +32,7 @@ #include "gdk-private.h" #include "gdkdeviceprivate.h" #include "gdkdisplayprivate.h" +#include "gdkdragsurfaceprivate.h" #include "gdkeventsprivate.h" #include "gdkframeclockidleprivate.h" #include "gdkglcontextprivate.h" @@ -113,12 +114,15 @@ static GParamSpec *properties[LAST_PROP] = { NULL, }; static void gdk_surface_popup_init (GdkPopupInterface *iface); static void gdk_surface_toplevel_init (GdkToplevelInterface *iface); +static void gdk_surface_drag_surface_init (GdkDragSurfaceInterface *iface); G_DEFINE_ABSTRACT_TYPE_WITH_CODE (GdkSurface, gdk_surface, G_TYPE_OBJECT, G_IMPLEMENT_INTERFACE (GDK_TYPE_POPUP, gdk_surface_popup_init) G_IMPLEMENT_INTERFACE (GDK_TYPE_TOPLEVEL, - gdk_surface_toplevel_init)) + gdk_surface_toplevel_init) + G_IMPLEMENT_INTERFACE (GDK_TYPE_DRAG_SURFACE, + gdk_surface_drag_surface_init)) static gboolean gdk_surface_real_beep (GdkSurface *surface) @@ -2176,6 +2180,27 @@ gdk_surface_toplevel_init (GdkToplevelInterface *iface) iface->show_window_menu = gdk_toplevel_surface_show_window_menu; } +static gboolean +gdk_drag_surface_real_present (GdkDragSurface *drag_surface, + int width, + int height) +{ + GdkSurface *surface = GDK_SURFACE (drag_surface); + + g_return_val_if_fail (surface->surface_type == GDK_SURFACE_TEMP, FALSE); + + GDK_SURFACE_GET_CLASS (surface)->toplevel_resize (surface, width, height); + gdk_surface_show_internal (surface, TRUE); + + return TRUE; +} + +static void +gdk_surface_drag_surface_init (GdkDragSurfaceInterface *iface) +{ + iface->present = gdk_drag_surface_real_present; +} + static void gdk_surface_set_cursor_internal (GdkSurface *surface, GdkDevice *device, diff --git a/gdk/meson.build b/gdk/meson.build index 0c1a277549..ac14c3b6fe 100644 --- a/gdk/meson.build +++ b/gdk/meson.build @@ -48,6 +48,7 @@ gdk_public_sources = files([ 'gdkpopup.c', 'gdktoplevellayout.c', 'gdktoplevel.c', + 'gdkdragsurface.c', ]) gdk_public_headers = files([ @@ -95,6 +96,7 @@ gdk_public_headers = files([ 'gdkpopup.h', 'gdktoplevellayout.h', 'gdktoplevel.h', + 'gdkdragsurface.h', ]) install_headers(gdk_public_headers, subdir: 'gtk-4.0/gdk/') -- 2.30.2